package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.dto.UserAddDto;
import top.api.domain.dto.UserEditDto;
import top.api.mapper.UserMapper;
import top.api.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Api(tags = "用户管理")
public class UserController {
    private final UserService baseService;

    @GetMapping
    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> pageList(@Validated PageDto pageDto,Integer id,String username){
        return baseService.pageList(pageDto,id,username);
    }

    @GetMapping("/{id}")
    @SaCheckRole("admin")
    @ApiOperation("查询用户详情")
    public ResUlt<?> getUserInfo(@PathVariable Integer id){
        return baseService.getUserInfo(id);
    }

    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加用户")
    public ResUlt<?> addUser(@RequestBody @Validated UserAddDto userAddDto){
        return baseService.addUser(userAddDto);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("修改用户")
    public ResUlt<?> editUser(@RequestBody @Validated UserEditDto userEditDto){
        return baseService.editUser(userEditDto);
    }


    @DeleteMapping("/{ids}")
    @SaCheckRole("admin")
    @ApiOperation("删除用户")
    public ResUlt<?> delUser(@PathVariable List<Integer> ids){
        return baseService.delUser(ids);
    }
}
